package com.api.gbhg.huangwm.web;

import com.customization.commons.LogTool;
import com.engine.common.util.ParamUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@Path("/gb/gwk")
public class GetYggwkApi {
    private LogTool logTool = new LogTool("/log/gbhg/huangwm/web/GetYggwkApi",false);

    /**
     * 获取员工公务卡
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/Getyggwk")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> Getyggwk(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        logTool.writeLog("=====获取员工公务卡=====");
        Map<String, Object> apiResult = new HashMap<String, Object>();
        Map<String, Object> requestParams = ParamUtil.request2Map(request);
        String bxr = requestParams.get("bxr").toString();
        try {
            RecordSet rs = new RecordSet();
            rs.execute("select *,(select lastname from hrmresource where id=yg) as lastname from uf_yggwktz where yg="+bxr);
            rs.next();
            apiResult.put("field20559", Util.null2String(rs.getString("id")));
            //apiResult.put("field20554", bxr);
            apiResult.put("field20551", Util.null2String(rs.getString("gwkh")));
            apiResult.put("field20549", Util.null2String(rs.getString("khx")));
            apiResult.put("field20554", Util.null2String(rs.getString("lastname")));
            apiResult.put("status", true);
            apiResult.put("errorCode", "1");
            apiResult.put("msg", "获取员工公务卡成功");
            return apiResult;
        }catch (Exception e){
            apiResult.put("status", false);
            apiResult.put("errorCode", "-999");
            apiResult.put("msg", "获取员工公务卡异常");
            e.printStackTrace();
        }
        return apiResult;
    }


    /**
     * 获取员工工资卡
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/Getyggzk")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> Getyggzk(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        logTool.writeLog("=====获取员工工资卡=====");
        Map<String, Object> apiResult = new HashMap<String, Object>();
        Map<String, Object> requestParams = ParamUtil.request2Map(request);
        String bxr = requestParams.get("bxr").toString();
        try {
            RecordSet rs = new RecordSet();
            rs.execute("select *,(select lastname from hrmresource where id=ygxm) as lastname from uf_yggzktz where ygxm="+bxr);
            rs.next();
            apiResult.put("field20559", Util.null2String(rs.getString("id")));
            //apiResult.put("field20554", bxr);
            apiResult.put("field20551", Util.null2String(rs.getString("yxkh")));
            apiResult.put("field20549", Util.null2String(rs.getString("khx")));
            apiResult.put("field20554", Util.null2String(rs.getString("lastname")));
            apiResult.put("gzh", Util.null2String(rs.getString("gzh")));
            apiResult.put("status", true);
            apiResult.put("errorCode", "1");
            apiResult.put("msg", "获取员工工资卡成功");
            return apiResult;
        }catch (Exception e){
            apiResult.put("status", false);
            apiResult.put("errorCode", "-999");
            apiResult.put("msg", "获取员工工资卡异常");
            e.printStackTrace();
        }
        return apiResult;
    }
}
